#include "stdafx.h"
#include "Nervus.h"


CNervus::CNervus(void)
{
	for( int i=0; i< NERVUS_ANTENNA_NUM; i++ )
	{
		m_pInputNervusAntenna[i] = new CNervusAntenna(this, 0);
		m_pOutputNervusAntenna[i] = new CNervusAntenna(this, i);
	}

	//m_bNoResponseStatus = false;
	//m_nExcitedCount = 0;
	//m_nSignalCount = 0;
	Complex CONST_CN;
	m_cValue = cn;
}


CNervus::~CNervus(void)
{
	for( int i=0; i< NERVUS_ANTENNA_NUM; i++ )
	{
		delete m_pInputNervusAntenna[i];
		delete m_pOutputNervusAntenna[i];
	}
}

void CNervus::ProcessSignal( void )
{
	Complex cResultSignal = m_pInputNervusAntenna[0]->GetSignal();

	for( int i=1; i< NERVUS_ANTENNA_NUM; i++ )
	{
		if( !m_pInputNervusAntenna[i]->IsNotConnected() )
			cResultSignal.Combine( m_pInputNervusAntenna[i]->GetSignal(), m_cValue ).Square();
	}

	for( int i=0; i< NERVUS_ANTENNA_NUM; i++ )
	{
		if( !m_pOutputNervusAntenna[i]->IsNotConnected() )
			m_pOutputNervusAntenna[i]->SetSignal( cResultSignal );
	}

}

void CNervus::DoSignalTransmition( void )
{
	for( int i=0; i< NERVUS_ANTENNA_NUM; i++ )
	{
		//TRACE( "%d:%d.", i, m_pOutputNervusAntenna[i]->ReadCurrentSignal() );
		m_pOutputNervusAntenna[i]->TransmitSignal();
	}
	//TRACE(".");
}

void CNervusMap::ProcessSignal( void )
{
	for( int j=0; j<NERVUS_MAP_DEPTH; j++ )
		for( int i=0; i<NERVUS_MAP_WIDTH; i++ )
			if( m_pNervusPool[i][j] )
				m_pNervusPool[i][j]->ProcessSignal();

	for( int j=0; j<NERVUS_MAP_DEPTH; j++ )
		for( int i=0; i<NERVUS_MAP_WIDTH; i++ )
			if( m_pNervusPool[i][j] )
			{
				//TRACE("[%d,%d]", i, j);
				m_pNervusPool[i][j]->DoSignalTransmition();
			}
	//TRACE("\n");

}
